package xyz.xtgl.employee.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.core.util.CommonUtil;
import common.core.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import plus.logic.LogicBaseController;
import xyz.xtgl.employee.entity.BEmployeeUser;
import xyz.xtgl.employee.feign.BEmployeeUserFeign;
import xyz.xtgl.employee.service.IBEmployeeUserService;

/**
 * <p>
 * 商户员工，用来收银登录时候用 前端控制器
 * </p>
 *
 * @author liubo
 * @since 2020-02-14
 */

@Slf4j
@Controller
@RequestMapping("/employee/b_employee_user")
public class BEmployeeUserController extends LogicBaseController<IBEmployeeUserService, BEmployeeUser> implements BEmployeeUserFeign{

    @Autowired
    private IBEmployeeUserService iBEmployeeUserService;

    /**
     * 跳转的列表页面
     * @return 跳转页面
     */
    @RequestMapping("/listPage")
    public Object listPage() {
      return "bEmployeeUser_list";
    }

    /**
     * 列表页面表格数据
     * @param query 查询条件
     * @param page 分页对象
     * @return page 分页对象
     */
    @ResponseBody
    @RequestMapping("/listData")
    public Result listData(QueryWrapper<BEmployeeUser> query, Page<BEmployeeUser> page) {
        return Result.success(iBEmployeeUserService.page(page, query));
    }

    /**
     * 跳转到修改页面
     * @param id 唯一主键
     * @param model Spring提供的绑定器
     * @return 修改页面
     */
    @RequestMapping("/editPage")
    public Object editPage(String id, Model model) {
        if(CommonUtil.isNotEmpty(id)) {
            BEmployeeUser entity = this.iBEmployeeUserService.getById(id);
            if(CommonUtil.isNotEmpty(entity)) {
                model.addAttribute("entity",entity);
            }
        }
        return "bEmployeeUser_edit";
    }

    /**
     * 数据保存
     * @param entity 实体类
     * @return Result 统一结果对象
     */
    @ResponseBody
    @RequestMapping("/saveOrUpdateEntity")
    public Result saveOrUpdateEntity(BEmployeeUser entity) {
        log.info("开始保存数据:{}" ,entity);
        this.iBEmployeeUserService.saveOrUpdate(entity);
        return Result.success();
    }

    /**
     * 数据删除
     * @param queryWrapper 删除条件
     * @return Result 统一结果对象
     */
    @ResponseBody
    @RequestMapping("/removed")
    public Result removed(QueryWrapper<BEmployeeUser> queryWrapper) {
        this.iBEmployeeUserService.remove(queryWrapper);
        return Result.success();
    }

}
